package com.mer.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Component
public class CorsOriginConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //代表当前类的所有请求都允许跨域
        registry.addMapping("/**")
                //配置哪个域允许访问
                .allowedOrigins("http://localhost:8080")
                //允许请求的方式
                .allowedMethods("*")
                //允许任意请求头
                .allowedHeaders("*");
    }
}